package com.ai.controller.made;

import com.ai.annotation.EnterPathParamLog;
import com.ai.common.CommonResponse;
import com.ai.entity.file.Audio;
import com.ai.entity.made.camera.CameraBO;
import com.ai.service.made.FileService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：xiaosheng
 * @Date：2024/5/15 10:16
 */

@RestController
@RequestMapping("/audio")
public class FileController {

    @Resource
    FileService fileService;


    /**
     * 上传音频信息到本地
     * @param file
     * @return
     */
    @PostMapping("/upload")
    @ApiOperation("音频文件上传")
    public CommonResponse insert(@RequestParam("audio") MultipartFile file) {



        return fileService.upload(file);
    }


    @PostMapping("/fileList")
    @ApiOperation("查询所有音频信息")
    public CommonResponse<List<Audio>> fileList(){

        List<Audio>list=fileService.list();
        return CommonResponse.ok(list);
    }

    /**
     * 通过ID查询
     *
     */
    @GetMapping("/oneById/{id}")
    @ApiOperation("通过ID查询")
    public CommonResponse<Audio> oneById(@PathVariable Integer id) {
        Audio resultData =fileService.oneById(id);
        return CommonResponse.ok(resultData);
    }


    /**
     * 修改音频名称
     * @return
     */
    @ApiOperation("修改信息")
    @PostMapping("/modifyInfo")
    public CommonResponse modifyInfo(@RequestBody Audio audio) {

        CommonResponse resultData = fileService.modifyInfo(audio);

        return resultData;
    }


    @ApiOperation("删除音频信息")
    @DeleteMapping("/deleteFile")
    public CommonResponse delete(@RequestBody Audio audio){
      CommonResponse commonResponse=  fileService.delete(audio);
      return commonResponse;
    }


    @PostMapping("/uploadToServer")
    @ApiOperation("上传文件到服务器")
    /**
     * fileId:文件Id
     * server:服务器Id
     */
    public CommonResponse uploadToServer(@RequestParam("fileId") Integer fileId,
                                         @RequestParam("serverId") Integer serverId){


        return fileService.uploadToServer(fileId,serverId);
    }


}
